<?php

include_once 'Leaf.php';

/**
 * This class represents a set of objects (typically a table)
 * @author Daniel Rivera
 */
class Set {
	
	var $children; //an array with every objects
	var $name; //typically the name of the table
	
	/**
	 * Conversion to output file in a format indicated by user
	 * @param format Output file format (xml, json)
	 * @return outputString A string containing specification of the object in the output type indicated.
	 */
	public function toString($format) {
		switch ($format) {
			case 'json':
				$outputString = '"' . $name . '": {';
				break;
			case 'xml':
				break;
		}
		for ($i=0; $i < len($this ->children); $i++) { 
			$item = $this ->children[i];
			try {
				$outputString .= $item -> toString($this -> name);
			} catch (exception $e) {
				echo 'Error trying to generate output string in element ' . i . ': ' . $e;
			}
		}
		$outputString .= '}';
		return $outputString;
	}
	
	/**
	 * Method for adding elements to the children array
	 * @param obj Object to be added to the children array. In case of being an array, it will be added at the end.
	 */
	public function addChild($obj) {
		if (is_array($obj)) {
			$this ->children = array_merge($this->children, $obj);
		} else {
			array_push($this->children, $obj);
		}
	}
	
}

?>